No — array indexes start at zero, and go up to length-1.
Here is a program that asks the user for an integer and for
an array index where it is to be placed.
Only indexes 0 through 9 are allowed.
Any other index causes an
IndexOutOfBoundsException.
import java.lang.* ;
import java.io.* ;
public class IndexPractice
{
public static void main ( String[] a ) throws IOException
{
BufferedReader stdin =
new BufferedReader ( new InputStreamReader( System.in ) );
String inData; int data=0, slot=0 ;
int[] value = new int[10];
try
{
System.out.println("Enter the data:");
inData = stdin.readLine();
data = Integer.parseInt( inData );
System.out.println("Enter the array index:");
inData = stdin.readLine();
slot = Integer.parseInt( inData );
value[slot] = data;
}
catch (NumberFormatException ex )
{
System.out.println("This is your problem: " + ex.getMessage()
+ "\nHere is where it happened:\n");
ex.printStackTrace();
}
catch (IndexOutOfBoundsException ex )
{
System.out.println("This is your problem: " + ex.getMessage()
+ "\nHere is where it happened:\n");
ex.printStackTrace();
}
System.out.println("Good-by" );
}
}